package com.zhangxin.aiInterview.manager.redis.stress_detector;

import com.zhangxin.aiInterview.model.enums.InterviewTypeEnum;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 消息消费者
 */


@Component
@AllArgsConstructor
public class StressDetectionConsumer {

    private final StringRedisTemplate redisTemplate;

    /**
     * 消费消息
     * @param userId
     * @param interviewType
     * @return
     */
    public String startConsuming(Long userId, Integer interviewType) {
        if(Objects.equals(interviewType, InterviewTypeEnum.TEC_INTERVIEW.getValue())){
            String queueKey = "AI_interview:tec_interview:stress_detector:" + userId;
            // 阻塞式右弹出（0表示无限等待）
            String message = redisTemplate.opsForList().rightPop(queueKey, 0, java.util.concurrent.TimeUnit.SECONDS);
            if (message != null) {
                System.out.println("[消费者] 处理消息: " + message);
                // 在这里添加业务处理逻辑
                return message;
            }
        }else {
            String queueKey = "AI_interview:hr_interview:stress_detector:" + userId;
            // 阻塞式右弹出（0表示无限等待）
            String message = redisTemplate.opsForList().rightPop(queueKey, 0, java.util.concurrent.TimeUnit.SECONDS);
            if (message != null) {
                System.out.println("[消费者] 处理消息: " + message);
                return message;
            }
        }
        return null;
    }
}